import {
      GET_SWIPERLIST,GET_ICONSLIST,
      GET_MAINIMGS,
      GET_RECOMMENDSLIST,
      GET_SEARCHSLIST,
      GET_SEARCH,
      GET_CARS
} from "./mutations-types";
import axios from "axios";

const actions={
       //swiper
      getSwiperFn({commit}){
           axios.get("/api/swiperList").then((res)=>{
                 //console.log(res.data)
                 commit(GET_SWIPERLIST,res.data)
           })
      },

      //icon
      getIconsFn({commit}){
            axios.get("/api/iconsList").then((res)=>{
                  //console.log(res.data)
                  commit(GET_ICONSLIST,res.data)
            })
       },

       //首页img
       getImgsFn({commit}){
            axios.get("/api/mainImgs").then((res)=>{
                  //console.log(res.data)
                  commit(GET_MAINIMGS,res.data)
            })
       },

       //推荐数据
       getRecommendsFn({commit},obj){
            //console.log(obj)
            axios.get(`/api/recommendslist?index=${obj.index}&listLength=${obj.listLength}`).then((res)=>{
                  //console.log(res.data)
                  commit(GET_RECOMMENDSLIST,res.data)
            })
            //obj.callBack()
       },

       //search 列表数据
       getSearchsListFn({commit}){
            axios.get("/api/searchsList").then((res)=>{
                  //console.log(res.data.searchData.data)
                  commit(GET_SEARCHSLIST,res.data.searchData.data)
            })
       },

       //搜索功能结果的数据
	async getSearch({commit},val){

		await axios.get("/api/search?q="+val+"").then(res=>{
			commit(GET_SEARCH,res.data.results);

		})

      },
      
      //购物车数据
	// async getCarsFn({commit}){
	// 	await axios.get("/api/shopcars").then(res=>{
	// 		commit(GET_CARS,res.data.results);
	// 	})
	// },
}

export default actions;